<?php
/**
 * author: Group One
 * date: 5th May 2014
 * description: A root class to manage functions. This class provides the basic functions of insertion, deletion, updating, and getting
 */
include_once("adb.php");
class opdClass extends adb{
        function opdClass(){
            adb::adb();
        }
        
//GET functions
        function get_community_member_opd_records($community_member_id){
            $query="select * from community_member_opd_records where community_member_id = $community_member_id";
            return $this->query($query);
        }

        function get_community_member($community_member_id){
            $query = "select * from community_members where community_member_id = $community_member_id";
            return $this->query($query);
        }
        
        function get_opd_case($opd_case_id){
            $query = "select * from opd_cases where opd_case_id = $opd_case_id"; 
            return $this->query($query);
        }
		
		function get_opd_cases(){
			$query = "select * from opd_cases";
            return $this->query($query);
			}

        function get_opd_record($record_id){
            $query = "select * from opd_record where record_id = $record_id";
            return $this->query($query);
        }

        function get_opd_records(){
            $query = "select * from opd_record";
            return $this->query($query);
        }

        function get_cho($idcho){
            $query = "select * from cho where idcho = $idcho";
            return $this->query($query);
        }

        function opd_rec_search($community_member_id){
            $query = "select * from opd_record where community_member_id = $community_member_id";
            return $this->query($query);
        }


//UPDATE functions
        function update_community_member_opd_records($rec_no, $community_member_id, $opd_case_id, $rec_date, $cho_id, $device_id, $deviceRecNo, $community_id){
            $query="update community_member_opd_records set rec_date = '$rec_date', cho_id = '$cho_id', device_id = '$device_id', 
            deivceRecNo = '$deviceRecNo', community_id = '$communty_id' where community_member_id = $community_member_id";
            return $this->query($query);
        }
        
        function update_opd_case($opd_case_id, $opd_case_name, $opd_case_category){
            $query = "update opd_cases set opd_case_name = '$opd_case_name', opd_case_category = '$opd_case_category' where opd_case_id = $opd_case_id"; 
            return $this->query($query);
        }

        function update_opd_record($record_id, $community_member_id, $opd_case_id, $record_type, $idcho, $note){
            $query = "update opd_record set community_member_id = '$community_member_id', opd_case_id = '$opd_case_id', 
            record_type = '$record_type', idcho = '$idcho', note = '$note' where record_id = $record_id";
            return $this->query($query);
        }

//DELETE functions
        function delete_community_member_opd_records($community_member_id){
            $query="delete from community_member_opd_records where community_member_id = $community_member_id";
            return $this->query($query);
        }
        
        function delete_opd_case($opd_case_id){
            $query = "delete from opd_cases where opd_case_id = $opd_case_id"; 
            return $this->query($query);
        }

        function delete_opd_record($record_id){
            $query = "delete from opd_record where record_id = $record_id";
            return $this->query($query);
        }
        

//INSERT functions
        function insert_community_member_opd_records($community_member_id, $opd_case_id, $rec_date, $cho_id, $device_id, $deviceRecNo, $community_id){
            $query="insert into community_member_opd_records set community_member_id = '$community_member_id', opd_case_id = '$opd_case_id', 
            rec_date = '$rec_date', cho_id = '$cho_id', device_id = '$device_id', deivceRecNo = '$deviceRecNo', community_id = '$communty_id'";
            return $this->query($query);
        }
        
        function insert_opd_case($opd_case_name, $opd_case_category){
            $query = "insert into opd_cases set opd_case_name = '$opd_case_name', opd_case_category = $opd_case_category"; 
            return $this->query($query);
        }

        function insert_opd_record($community_member_id, $opd_case_id, $record_type, $idcho, $note){
            $query = "insert into opd_record set community_member_id = '$community_member_id', opd_case_id = '$opd_case_id', record_type = '$record_type', 
            idcho = '$idcho', note = '$note'";
            return $this->query($query);
        }
    }

    //Testing 
    /*$obj = new vaccines();
    if(!$obj->get_all_vaccines()){
        echo "Error";   
    }
    $row = $obj->fetch();
    while($row){
        print_r($row);
        $row = $obj->fetch();
    }
    */
?>